{include file="public/top" /}

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <input name="id" type="hidden" value="{$data.id}">
            <div class="layui-form-item">
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <span class="x-red">*</span>分类
                    </label>
                    <div class="layui-input-inline">
                        <select id="type_id" name="type_id" class="valid">
                            {volist name="type" id="v"}
                            <option value="{$v.id}"  {if $v.id eq $data.type_id}selected="selected"{/if}>{$v.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <label class="layui-form-label">
                    <span class="x-red">*</span>名称
                </label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" value="{$data.name}" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <br>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <span class="x-red">*</span>标题(SEO)
                    </label>
                    <div class="layui-input-block">
                        <input type="text" id="title" name="title" value="{$data.title}" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>

                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <span class="x-red">*</span>关键词(SEO)
                    </label>
                    <div class="layui-input-block">
                        <input type="text" id="keyword" name="keyword" value="{$data.keyword}" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <span class="x-red">*</span>描述(SEO)
                    </label>
                    <div class="layui-input-block">
                        <textarea style="width: 1500px;height: 100px" name="description">{$data.description}</textarea>
                    </div>
                </div>
                <br>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="margin: 20px 0 0 0;"> <span class="x-red">*</span>封面</label>
                    <label for="test1">
                    <span id="imgg1">
                    <img style="height: 80px;width: 120px;margin: 0 10px 0 0;cursor:pointer;" src="{$data.img_url}">
                    </span>
                        <span>尺寸：738*420</span>
                    </label>
                    <span id="t1"></span>
                    <button type="button" style="margin: 5px 0 0 0;display: none" class="layui-btn layui-btn-small" id="test1">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
                <br>
                <label class="layui-form-label">
                    <span class="x-red">*</span>图片Alt
                </label>
                <div class="layui-input-block">
                    <input type="text" id="alt" name="alt" required="" value="{$data.alt}" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <br>
                <div>
                    <span class="x-red">*</span>介绍
                    <script type="text/plain" id="editor1" class="ueueueue">{$data.intro}</script>
                    <div class="con-split" style="height: 100px;"></div>
                </div>
                <br>
                <div>
                    <span class="x-red">*</span>内容
                    <script type="text/plain" id="editor" class="ueueueue">{$data.content}</script>
                    <div class="con-split" style="height: 100px;"></div>
                </div>
                <br>
            </div>


        <div class="layui-form-item">
            <button type="button"  class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="">提交</button>
        </div>
    </form>
</div>
<script>

    var addurl = '/admin/Bujian/up';
    var imgupUrl = '/admin/index/imgUp';
    var ue = UE.getEditor('editor',{
        textarea:'editorValue'
    });
    var ue1 = UE.getEditor('editor1',{
        textarea:'value'
    });
    //编辑器
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });
        //监听提交
        form.on('submit(add)', function(data){
            $.post(addurl, data.field,function(res) {
                var success = JSON.parse(res);
                if(success.code===200){
                    layer.msg(success.msg, {
                        time: 1000, //不自动关闭
                        icon:6,
                        end:function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                    });
                    return false;
                }else {
                    layer.msg(success.msg)
                }


            });

        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: imgupUrl //上传接口
            ,done: function(res){
                var  option = '<img style="height: 80px;width: 120px;margin: 0 10px 0 0;cursor:pointer;" src="'+res.data+'">';
                $('#imgg1').html(option);
                var addBox = '<input type="hidden" name="img_url" value="'+res.data+'">';
                document.getElementById('t1').innerHTML += addBox;
            }
            ,error: function(){
                //请求异常回调
            }
        });

    });
</script>


</body>

</html>